﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SEBanking
{
    public partial class WebForm5 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"].ToString() == String.Empty)
                Response.Redirect("~/Index.aspx");

            if (!IsPostBack)
            {
                DataClasses1DataContext context = new DataClasses1DataContext();
                var query = from a in context.SEBanking_Accounts
                            where a.Acc_ID == Session["UserID"].ToString()
                            select new { AccID = a.Acc_ID, AccName = a.Acc_Name, AccEmail = a.Acc_Mail, Password = a.Acc_Password };
                foreach (var q in query)
                {
                    txtName.Text = q.AccName.Trim();
                    txtPassword.Text = q.Password.Trim();
                    txtEmail.Text = q.AccEmail.Trim();
                }
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            DataClasses1DataContext context = new DataClasses1DataContext();

            var a = context.SEBanking_Accounts.Single(c=>c.Acc_ID == Session["UserID"].ToString());
            a.Acc_Name = txtName.Text;
            a.Acc_Password = txtPassword.Text;
            a.Acc_Mail = txtEmail.Text;
            context.SubmitChanges();
            lblResult.Text = "Update succeeded";
            Session["UserName"] = txtName.Text;
        }
    }
}
